package com.jzwl.site.wap.party.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.base.Objects;
import com.jzwl.common.constant.AjaxStatusConstant;
import com.jzwl.common.constant.Constants;
import com.jzwl.common.constant.WeixinUserInfoDto;
import com.jzwl.enums.DataTypeEnum;
import com.jzwl.site.manager.complaint.service.BusinessCircleComplaintService;
import com.jzwl.site.manager.interaction.service.BusinessCircleInteractionService;
import com.jzwl.site.manager.tradingareainfo.service.TradingAreaInfoService;
import com.jzwl.site.manager.tradingareashopinfo.service.TradingAreaShopInfoService;
import com.jzwl.site.manager.tradingcarparkinfo.service.TradingCarParkInfoService;
import com.jzwl.site.wap.articlefabulous.service.SiteArticleUserFabulousService;
import com.jzwl.site.wap.articlestudy.service.SiteArticleUserStudyService;
import com.jzwl.site.wap.party.service.PartyService;
import com.jzwl.site.wap.wxUser.service.WxUserService;
import com.jzwl.system.admin.dicdate.service.DicDataService;
import com.jzwl.system.base.controller.BaseController;

//https://oapi.dingtalk.com/robot/send?access_token=ea85d23210b00a7c0452e4187e11272d6bec87664e202ba4ebf3fb2b8ba1242a
@Controller
@RequestMapping("/wap")
public class PartyController extends BaseController {

	@Autowired
	private PartyService partyService;

	@Autowired
	private SiteArticleUserStudyService siteArticleUserStudyService;

	@Autowired
	private SiteArticleUserFabulousService siteArticleUserFabulousService;

	@Autowired
	private BusinessCircleComplaintService businessCircleComplaintService;//商圈信访投诉相关

	@Autowired
	private BusinessCircleInteractionService businessCircleInteractionService;//商圈互动

	@Autowired
	private WxUserService wxUserService;//获取用户相关

	@Autowired
	private DicDataService dicDataService;//字典相关

	@Autowired
	private TradingAreaInfoService tradingAreaInfoService;//区域相关

	@Autowired
	private TradingAreaShopInfoService tradingAreaShopInfoService;

	@Autowired
	private TradingCarParkInfoService tradingCarParkInfoService;//停车场相关

	@Autowired
	private Constants constants;

	/**
	 * 根据类型，获取数据
	 * @param type
	 * @param request
	 * @param response
	 * @return TODO(这里描述每个参数,如果有返回值描述返回值,如果有异常描述异常)
	 */
	@RequestMapping(value = "/{type}")
	public @ResponseBody Map<String, Object> acquisitionData(@PathVariable String type, HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();

		try {
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_SUCCESS);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_SUCCESS);
			//dwjs：党务建设
			if (Objects.equal(type, DataTypeEnum.dwjs.getName())) {
				Map<String, Object> map_dwjs = partyService.query_dwjs();
				resultMap.put("resourceInfo", map_dwjs);
			} else if (Objects.equal(type, DataTypeEnum.dfjs.getName())) {
				Map<String, Object> map_dfjs = partyService.query_dfjs();
				resultMap.put("resourceInfo", map_dfjs);
			} else if (Objects.equal(type, DataTypeEnum.lljs.getName())) {
				Map<String, Object> map_dfjs = partyService.query_lljs();
				resultMap.put("resourceInfo", map_dfjs);
			} else if (Objects.equal(type, DataTypeEnum.wssq.getName())) {
				Map<String, Object> map = partyService.query_wssq();
				resultMap.put("resourceInfo", map);
			} else if (Objects.equal(type, DataTypeEnum.fwsq.getName())) {
				List list = partyService.queryNodeByType(type, false);
				resultMap.put("resourceInfo", list);
			} else if (Objects.equal(type, DataTypeEnum.pasq.getName())) {
				List list = partyService.queryNodeByType(type, false);
				resultMap.put("resourceInfo", list);
			} else if (Objects.equal(type, DataTypeEnum.pasq.getName())
					|| Objects.equal(type, DataTypeEnum.zjsq.getName())) {
				List list = partyService.queryNodeByType(type, false);
				resultMap.put("resourceInfo", list);
			} else if (Objects.equal(type, DataTypeEnum.fwsq_xedk.getName())
					|| Objects.equal(type, DataTypeEnum.fwsq_flwq.getName())
					|| Objects.equal(type, DataTypeEnum.fwsq_swzx.getName())
					|| Objects.equal(type, DataTypeEnum.fwsq_sqwy.getName())
					|| Objects.equal(type, DataTypeEnum.zjsq_fgrsscjysfz.getName())
					|| Objects.equal(type, DataTypeEnum.zjsq_scglryzcxcz.getName())
					|| Objects.equal(type, DataTypeEnum.zjsq_gtshbfz.getName())
					|| Objects.equal(type, DataTypeEnum.zjsq_zyzyhjwszzz.getName())
					|| Objects.equal(type, DataTypeEnum.zjsq_dgpt.getName())
					|| Objects.equal(type, DataTypeEnum.zjsq_sqcf.getName())) {
				Map map = partyService.queryArticleInfoByType(type);
				resultMap.put("resourceInfo", map);
			} else if (Objects.equal(type, DataTypeEnum.dwjs_jjfz.getName())
					|| Objects.equal(type, DataTypeEnum.dwjs_dydw.getName())
					|| Objects.equal(type, DataTypeEnum.dfjs_dflz.getName())
					|| Objects.equal(type, DataTypeEnum.dfjs_sfjs.getName())
					|| Objects.equal(type, DataTypeEnum.lljs_llxx.getName())
					|| Objects.equal(type, DataTypeEnum.lljs_dyhd.getName())
					|| Objects.equal(type, DataTypeEnum.lljs_jljt.getName())
					|| Objects.equal(type, DataTypeEnum.fwsq_rczp.getName())
					|| Objects.equal(type, DataTypeEnum.fwsq_rcpx.getName())
					|| Objects.equal(type, DataTypeEnum.fwsq_ghfl.getName())
					|| Objects.equal(type, DataTypeEnum.wssq_csws.getName())
					|| Objects.equal(type, DataTypeEnum.wssq_cszx.getName())
					|| Objects.equal(type, DataTypeEnum.pasq_aqsc.getName())
					|| Objects.equal(type, DataTypeEnum.pasq_xfaq.getName())
					|| Objects.equal(type, DataTypeEnum.pasq_rjjz.getName())
					|| Objects.equal(type, DataTypeEnum.pasq_shce.getName())
					|| Objects.equal(type, DataTypeEnum.pasq_shdf.getName())
					|| Objects.equal(type, DataTypeEnum.zjsq_sqdt.getName())) {
				List list = partyService.queryByType(type, false);
				resultMap.put("resourceInfo", list);
			}
		} catch (Exception e) {
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_FAILURE);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_FAILE);
		}
		return resultMap;
	}

	/**
	 * 获取文章的详情 openId,articleId
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/queryArticleInfoByArticleId")
	public @ResponseBody Map<String, Object> queryArticleInfoByArticleId(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			createParameterMap(request);
			//添加学习信息
			boolean flag1 = siteArticleUserStudyService.addSiteArticleUserStudy(paramsMap);
			//更新文章查看的数量
			boolean flag2 = partyService.updateSeeNum(paramsMap);
			//获取文章的详情
			Map articleInfo = partyService.queryArticleInfoByArticleId(paramsMap);
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_SUCCESS);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_SUCCESS);
			resultMap.put("resourceInfo", articleInfo);
		} catch (Exception e) {
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_FAILURE);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_FAILE);
			resultMap.put("resourceInfo", "操作失败");
		}
		return resultMap;
	}

	/**
	 * 获取文章的详情 openId,articleId
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/queryArticleInfoById")
	public @ResponseBody Map<String, Object> queryArticleInfoById(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			createParameterMap(request);
			String articleId = paramsMap.get("articleId").toString();
			//更新文章查看的数量
			boolean flag2 = partyService.updateSeeNum(paramsMap);
			//获取文章的详情
			Map articleInfo = partyService.queryArticleInfoByArticleId(paramsMap);
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_SUCCESS);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_SUCCESS);
			resultMap.put("resourceInfo", articleInfo);
		} catch (Exception e) {
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_FAILURE);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_FAILE);
			resultMap.put("resourceInfo", "操作失败");
		}
		return resultMap;
	}

	/**
	 * 获取学习人员列表的接口 articleId
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/queryStudyList")
	public @ResponseBody Map<String, Object> queryStudyList(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			createParameterMap(request);
			//获取文章学习人员列表
			List articleInfos = siteArticleUserStudyService.querySiteArticleUserStudyList(paramsMap);
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_SUCCESS);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_SUCCESS);
			resultMap.put("resourceInfo", articleInfos);
		} catch (Exception e) {
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_FAILURE);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_FAILE);
			resultMap.put("resourceInfo", "失败");
		}
		return resultMap;
	}

	/**
	 * 文章点赞的接口 openId articleId
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/fabulous")
	public @ResponseBody Map<String, Object> fabulous(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			createParameterMap(request);
			//点赞设置
			int temp = siteArticleUserFabulousService.siteArticleUserFabulous(paramsMap);
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_SUCCESS);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_SUCCESS);
			//0:点赞，1：取消点赞
			resultMap.put("resourceInfo", temp);
		} catch (Exception e) {
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_FAILURE);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_FAILE);
			resultMap.put("resourceInfo", "失败");
		}
		return resultMap;
	}

	/**
	 * 判断该用户是否点赞过该文章 openId articleId
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/queryFabulous")
	public @ResponseBody Map<String, Object> queryFabulous(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			createParameterMap(request);
			//点赞设置
			List temp = siteArticleUserFabulousService.querySiteArticleUserFabulous(paramsMap);
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_SUCCESS);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_SUCCESS);
			//0:点赞，1：取消点赞
			resultMap.put("resourceInfo", temp);
		} catch (Exception e) {
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_FAILURE);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_FAILE);
			resultMap.put("resourceInfo", "失败");
		}
		return resultMap;
	}

	/**
	 * 商圈信访投诉存储   :content,:openId,:userName,
	 * @param request
	 * @param response
	 * @return TODO(这里描述每个参数,如果有返回值描述返回值,如果有异常描述异常)
	 */
	@RequestMapping(value = "/addComplaint")
	public @ResponseBody Map<String, Object> addComplaint(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			createParameterMap(request);
			//点赞设置
			boolean temp = businessCircleComplaintService.addBusinessCircleComplaint(paramsMap);
			if (temp) {
				resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_SUCCESS);
				resultMap.put("code", AjaxStatusConstant.AJAX_CODE_SUCCESS);
				resultMap.put("resourceInfo", "成功");
			} else {
				resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_FAILURE);
				resultMap.put("code", AjaxStatusConstant.AJAX_CODE_FAILE);
				resultMap.put("resourceInfo", "失败");
			}

		} catch (Exception e) {
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_FAILURE);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_FAILE);
			resultMap.put("resourceInfo", "失败");
		}
		return resultMap;
	}

	/**
	 * 商圈互动信息存储   :content,:openId,:userName,
	 * @param request
	 * @param response
	 * @return TODO(这里描述每个参数,如果有返回值描述返回值,如果有异常描述异常)
	 */
	@RequestMapping(value = "/addInteraction")
	public @ResponseBody Map<String, Object> addInteraction(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			createParameterMap(request);
			//点赞设置
			boolean temp = businessCircleInteractionService.addBusinessCircleInteraction(paramsMap);
			if (temp) {
				resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_SUCCESS);
				resultMap.put("code", AjaxStatusConstant.AJAX_CODE_SUCCESS);
				resultMap.put("resourceInfo", "成功");
			} else {
				resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_FAILURE);
				resultMap.put("code", AjaxStatusConstant.AJAX_CODE_FAILE);
				resultMap.put("resourceInfo", "失败");
			}

		} catch (Exception e) {
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_FAILURE);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_FAILE);
			resultMap.put("resourceInfo", "失败");
		}
		return resultMap;
	}

	/**
	 * 根据code获取用户信息 code
	 * @Date 2019年5月15日
	 * @author gyp
	 * @param request
	 * @param response
	 * @return(这里描述每个参数,如果有返回值描述返回值,如果有异常描述异常)
	 */
	@RequestMapping(value = "/userInfo")
	public @ResponseBody Map<String, Object> userInfo(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			createParameterMap(request);
			String code = paramsMap.get("code").toString();
			WeixinUserInfoDto userInfo = wxUserService.userInfo(code);
			if (null != userInfo) {
				resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_SUCCESS);
				resultMap.put("code", AjaxStatusConstant.AJAX_CODE_SUCCESS);
				resultMap.put("resourceInfo", userInfo);
			} else {
				resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_FAILURE);
				resultMap.put("code", AjaxStatusConstant.AJAX_CODE_FAILE);
				resultMap.put("resourceInfo", userInfo);
			}

		} catch (Exception e) {
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_FAILURE);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_FAILE);
			resultMap.put("resourceInfo", null);
		}
		return resultMap;
	}

	/**
	 * 获取dicData数据 name
	 * @Date 2019年5月15日
	 * @author gyp
	 * @param request
	 * @param response
	 * @return(这里描述每个参数,如果有返回值描述返回值,如果有异常描述异常)
	 */
	@RequestMapping(value = "/dicData")
	public @ResponseBody Map<String, Object> dicData(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			createParameterMap(request);
			Map dicData = dicDataService.dicData(paramsMap);
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_SUCCESS);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_SUCCESS);
			resultMap.put("resourceInfo", dicData);

		} catch (Exception e) {
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_FAILURE);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_FAILE);
			resultMap.put("resourceInfo", null);
		}
		return resultMap;
	}

	/**
	 * 获取区域列表
	 * @param request
	 * @param response
	 * @return TODO(这里描述每个参数,如果有返回值描述返回值,如果有异常描述异常)
	 */
	@RequestMapping(value = "/queryAreaList")
	public @ResponseBody Map<String, Object> queryAreaList(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			createParameterMap(request);
			List areas = tradingAreaInfoService.queryList(paramsMap);
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_SUCCESS);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_SUCCESS);
			resultMap.put("resourceInfo", areas);
		} catch (Exception e) {
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_FAILURE);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_FAILE);
			resultMap.put("resourceInfo", "失败");
		}
		return resultMap;
	}

	/**
	 * 获取商店列表
	 * @param request
	 * @param response
	 * @return TODO(这里描述每个参数,如果有返回值描述返回值,如果有异常描述异常)
	 */
	@RequestMapping(value = "/queryShopList")
	public @ResponseBody Map<String, Object> queryShopList(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			createParameterMap(request);
			List areas = tradingAreaShopInfoService.queryList(paramsMap);
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_SUCCESS);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_SUCCESS);
			resultMap.put("resourceInfo", areas);
		} catch (Exception e) {
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_FAILURE);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_FAILE);
			resultMap.put("resourceInfo", "失败");
		}
		return resultMap;
	}

	/**
	 * 获取停车场列表
	 * @param request
	 * @param response
	 * @return TODO(这里描述每个参数,如果有返回值描述返回值,如果有异常描述异常)
	 */
	@RequestMapping(value = "/queryCarList")
	public @ResponseBody Map<String, Object> queryCarList(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			createParameterMap(request);
			List areas = tradingCarParkInfoService.queryList(paramsMap);
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_SUCCESS);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_SUCCESS);
			resultMap.put("resourceInfo", areas);
		} catch (Exception e) {
			resultMap.put("msg", AjaxStatusConstant.AJAX_STATUS_FAILURE);
			resultMap.put("code", AjaxStatusConstant.AJAX_CODE_FAILE);
			resultMap.put("resourceInfo", "失败");
		}
		return resultMap;
	}

}
